import { createRouter, createWebHashHistory } from 'vue-router';
import { Toast } from 'vant'
const router = createRouter({
    history: createWebHashHistory(),
    routes: [{
            path: '/',
            component: () =>
                import ('../pages/myHome/MyHome'),
        },
        {
            path: '/home',
            component: () =>
                import ('../pages/myHome/MyHome'),
        },
        {
            path: '/cart',
            component: () =>
                import ('../pages/myCart/MyCart'),
            meta: {
                isAuth: true,
            }
        },
        {
            path: '/order',
            component: () =>
                import ('../pages/myOrder/MyOrder'),
            meta: {
                isAuth: true,
            }
        },
        {
            path: '/mine',
            component: () =>
                import ('../pages/mine/Mine'),
            meta: {
                isAuth: true,
            }
        },
        {
            path: '/store',
            component: () =>
                import ('../pages/store/MyStore'),
        },
        {
            path: '/createorder',
            component: () =>
                import ('../pages/createOrder/CreateOrder.vue'),
            meta: {
                isAuth: true,
            }
        },
        {
            path: '/address',
            component: () =>
                import ('../pages/address/Address.vue'),
            meta: {
                isAuth: true,
            }
        },
        {
            path: '/addressedit',
            component: () =>
                import ('../pages/addressEdit/AddressEdit.vue'),
            meta: {
                isAuth: true,
            }
        },
        {
            path: '/login',
            component: () =>
                import ('../pages/login/Login.vue'),
        },
        {
            path: '/register',
            component: () =>
                import ('../pages/register/Register.vue'),
        },
        {
            path: '/userinfoedit',
            component: () =>
                import ('../pages/userinfoEdit/UserinfoEdit.vue'),
            meta: {
                isAuth: true,
            }
        },
    ],
});

router.beforeEach((to, from, next) => {
    if (to.meta.isAuth) {
        if (localStorage.isLogin === '11') {
            next();
        } else {
            Toast('请先登录')
            router.push('./login')
        }
    } else {
        next();
    }
})

export default router;